package com.example.platform.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.platform.web.config.ResultInfo;
import com.example.platform.web.config.Status;
import com.example.platform.web.entity.SysUser;
import com.example.platform.web.entity.SysUserVo;
import com.example.platform.web.service.ISysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/system/noAuth/sysUser")
public class SysUserController {

    @Resource
    private ISysUserService sysUserService;

    @PostMapping("/insert")
    public ResultInfo add(@RequestBody SysUser userParam){
        sysUserService.insertModel(userParam);
        return new ResultInfo(Status.SUCCESS);
    }

    @PostMapping("/delete")
    public ResultInfo delete(@RequestBody SysUser userParam){
        sysUserService.deleteByModel(userParam);
        return new ResultInfo(Status.SUCCESS);
    }

    @PostMapping("/update")
    public ResultInfo update(@RequestBody SysUser userParam){
        sysUserService.update(userParam);
        return new ResultInfo(Status.SUCCESS);
    }


    @PostMapping("/pageList")
    public ResultInfo pageList(@RequestBody SysUserVo sysUserVo){
        IPage<SysUser> pageInfo = sysUserService.selectByPage(sysUserVo);
        return new ResultInfo(Status.SUCCESS.code,pageInfo);
    }

    @PostMapping("/getModel")
    public ResultInfo  getModel(@RequestBody SysUser userParam){
        SysUser user =  sysUserService.findByModel(userParam);
        return new ResultInfo(Status.SUCCESS.code,user);
    }

    @PostMapping("/login")
    public ResultInfo  login(@RequestBody SysUser userParam){

        return sysUserService.login(userParam);
    }
}
